module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    copy: {
      main: {
        expand: true,
        cwd: 'src',
        src: '**',
        dest: '../dist/',
      },
    },

    cssmin: {
      compress: {
        files: [{
          expand: true,
          cwd: '../dist',
          src: ['**/*.css'],
          dest: '../dist'
        }]
      }
    },

    uglify: {
      build: {
        files: [{
          expand: true,
          cwd: '../dist',
          src: '**/*.js',
          dest: '../dist'
        }]
      }
    },

    concat: {
        options: {
            separator: ';\n',
        },
        dist: {
            src: [
                '../dist/components/**/*.js',
                '../dist/utils/*.js'
            ],
            dest: '../dist/pcall.js',
        }
    },

    babel: {
        options: {
            sourceMap: false,
            presets: ['@babel/preset-env']
        },
        dist: {
            expand: true,
            cwd: '../dist',
            src: '**/*.js',
            dest: '../dist'
        }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-babel');

  // 1. copy all files of src to dist
  // 2. 压缩 js
  // 3. 压缩 css
  // 4. 合并常用 js
  grunt.registerTask('default', ['copy', 'babel', 'uglify:build', 'cssmin:compress', 'concat', 'plugins']);

  grunt.registerTask('plugins', 'copy plugins to dist', () => {
      grunt.file.copy('./plugins', '../dist/plugins/');
  });

};
